home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / whdload / src / whdloadgci / dumpfile.c next >
C/C++ Source or Header  |  2000-02-28  |  3KB  |  144 lines

  1. /*****************************************************************************
  2. ;  :Module.        dumpfile.c
  3. ;  :Author.        Bert Jahn
  4. ;  :EMail.        jah@fh-zwickau.de
  5. ;  :Address.    Franz-Liszt-Straße 16, Rudolstadt, 07404, Germany
  6. ;  :Version.    $Id: dumpfile.c 0.3 1999/01/12 21:57:43 jah Exp $
  7. ;  :History.    18.07.98 started
  8. ;                13.12.98 dumpfilename from whdload.prefs
  9. ;  :Copyright.    All Rights Reserved
  10. ;  :Language.    C
  11. ;  :Tabsize.    4
  12. ;  :Translator.    SAS 6.58
  13. *****************************************************************************/
  14.  
  15. #include <libraries/iffparse.h>
  16. #include "whddump.h"
  17.  
  18. #include <clib/dos_protos.h>
  19. #include <clib/exec_protos.h>
  20. #include <clib/muimaster_protos.h>
  21.  
  22. #include <pragmas/muimaster_pragmas.h>
  23.  
  24. #include <string.h>
  25.  
  26. extern struct Library *MUIMasterBase;
  27. extern APTR app,win;
  28.  
  29. extern struct whddump_header    * header;
  30. extern struct whddump_cpu        * cpu;
  31. extern struct whddump_custom    * custom;
  32. extern struct whddump_cia        * ciaa;
  33. extern struct whddump_cia        * ciab;
  34. extern APTR                        * slave;
  35. extern APTR                        * mem;
  36.  
  37. /****************************************************************************/
  38.  
  39. APTR    * dumpfile = NULL;
  40.  
  41. /****************************************************************************/
  42.  
  43. void freedump(void) {
  44.     if (dumpfile) {
  45.         FreeVec(dumpfile);
  46.         dumpfile = NULL;
  47.     }
  48. }
  49.  
  50. BOOL loaddump(STRPTR name) {
  51.     BOOL ret = FALSE;
  52.     BPTR fh;
  53.     ULONG size;
  54.     ULONG *tmp;
  55.     char filename[256]="";
  56.     char s[256];
  57.     char *t;
  58.  
  59.     /*
  60.      * if there is no filename for the dump overgiven try to load
  61.      * whdload config and get the path from there
  62.      */
  63.     if (name) {
  64.         strcpy(filename,name);
  65.     } else {
  66.         fh = Open("S:whdload.prefs",MODE_OLDFILE);
  67.         if (fh) {
  68.             while (FGets(fh,s,256)) {
  69.                 if (strnicmp("coredumppath=",s,13) == 0) {
  70.                     t = strpbrk(&s[13]," \t\n\r");
  71.                     if (t) strncpy(filename,&s[13],t-s-13);
  72.                     else strcpy(filename,&s[13]);
  73.                     break;
  74.                 }
  75.             }
  76.             Close(fh);
  77.         }
  78.         strcat(filename,".whdl_dump");
  79.     }
  80.         
  81.     /*
  82.      * free any loaded dump
  83.      */
  84.     freedump();
  85.  
  86.     /*
  87.      * load dump
  88.      */
  89.     if (NULL == (fh = Open(filename,MODE_OLDFILE))) {
  90.             MUI_Request(app,win,0,NULL,"Ok","Could not open dumpfile \"%s\".",filename);
  91.         } else {
  92.         Seek(fh,0,OFFSET_END);
  93.         size = Seek(fh,0,OFFSET_BEGINNING);
  94.         if (dumpfile = AllocVec(size,0)) {
  95.             if (size == Read(fh,dumpfile,size)) {
  96.                 tmp = (ULONG*)dumpfile;
  97.                 if ((*tmp == ID_FORM) &&(*(tmp+2) == ID_WHDD)) {
  98.                     tmp += 3;
  99.                     size -= 12;
  100.                     while (size>0) {
  101.                         tmp += 2;
  102.                         size -= 8;
  103.                         switch (*(tmp-2)) {
  104.                         case ID_HEAD:
  105.                             header = (struct whddump_header*)tmp;
  106.                             break;
  107.                         case ID_CPU:
  108.                             cpu = (struct whddump_cpu*)tmp;
  109.                             break;
  110.                         case ID_CUST:
  111.                             custom = (struct whddump_custom*)tmp;
  112.                             break;
  113.                         case ID_CIAA:
  114.                             ciaa = (struct whddump_cia*)tmp;
  115.                             break;
  116.                         case ID_CIAB:
  117.                             ciab = (struct whddump_cia*)tmp;
  118.                             break;
  119.                         case ID_SLAV:
  120.                             slave = (APTR)tmp;
  121.                             break;
  122.                         case ID_MEM:
  123.                             mem = (APTR)tmp;
  124.                             break;
  125.                         }
  126.                         size -= *(tmp-1);
  127.                         tmp += (*(tmp-1))>>2;
  128.                     }
  129.                     ret = TRUE;
  130.                 }
  131.             }
  132.             if (!ret) {
  133.                 FreeVec(dumpfile);
  134.                 dumpfile = NULL;
  135.             }
  136.         }
  137.         Close(fh);
  138.     }
  139.     return ret;
  140. }
  141.  
  142. /****************************************************************************/
  143.  
  144.